package com.mifengkong.frwidget.webview;

import android.webkit.WebView;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */

public class BaseWebViewUIComponent extends BaseWebViewSetting {

    private List<String> historyUrlList = new ArrayList<>();

    public static BaseWebViewUIComponent build(WebView view) {
        return build(BaseWebViewUIComponent.class, view);
    }

    @Override
    public void onPageFinished(String url) {
        super.onPageFinished(url);
        if (!historyUrlList.contains(url) && !isUrlBeContained(url)) {
            historyUrlList.add(url);
        }
    }

    public List<String> getHistoryUrlList() {
        return historyUrlList;
    }

    private boolean isUrlBeContained(String url) {
        for (int i = 0; i < historyUrlList.size(); i++) {
            if (historyUrlList.get(i).contains(url) || url.contains(historyUrlList.get(i))) {
                return true;
            }
        }
        return false;
    }
}